from omegaconf import OmegaConf

from zs_config.cmdline_load import CmdlineConfigLoader
from zs_config.common import LocalFilesystemLoader, iterate_loaders,ElasticserchLoader,OSSLoader, HiveLoader
# from zs_config.es_load import EsConfigLoader

class LocalConfigLoader(LocalFilesystemLoader):
    def get_load_paths(self):
        return self.bootstrap_cfg.config.local.config_paths

    def proc_file_data(self, file_handle):
        return OmegaConf.load(file_handle)

    def get_file_type(self):
        return 'config'

_loader_class_map = {
    'cmdline': CmdlineConfigLoader,
    'local': LocalConfigLoader,
    'es': ElasticserchLoader,
    'oss': OSSLoader,
    'hive': HiveLoader
}

def load_configs(bootstrap_cfg):
    return iterate_loaders(bootstrap_cfg.config.loaders,
                           _loader_class_map, (bootstrap_cfg,))
